package com.example.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 * @Description
 * @Date 2021/7/11
 * @Created by Jonathan
 */
@Slf4j
@Service
public class AsyncService implements BeanFactoryAware {

    private BeanFactory beanFactory;
    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    @PostConstruct
    public void test() {
        log.info("test method...");
        test1();
        AsyncService asyncService = (AsyncService) beanFactory.getBean(AsyncService.class);
        asyncService.test2();
    }

    @Async
    public void test1() {
        log.info("AsyncService test-1 method");
    }

    @Async
    public void test2() {
        log.info("AsyncService test-2 method");
    }

}
